package com.chain.BrotherExchange.utils;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间工具类
 */
@SuppressLint("SimpleDateFormat")
public class DateUtils {

    /**
     * 获取指定时间戳 一周后时间戳
     */
    public static long weekLaterTimestamp(long timestamp) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(timestamp));
        c.add(Calendar.DATE, -7);
        return c.getTime().getTime() / 1000;
    }

    /**
     * 获取指定时间戳 一个月后的时间戳
     */
    public static long afterMonthTimestamp(long timestamp) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(timestamp));
        c.add(Calendar.MONTH, -1);
        return c.getTime().getTime() / 1000;
    }

    /**
     * 获取指定时间戳 二个月后的时间戳
     */
    public static long afterTwoMonthTimestamp(long timestamp) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(timestamp));
        c.add(Calendar.MONTH, -2);
        return c.getTime().getTime() / 1000;
    }

    /**
     * 获取指定时间戳 半年后的时间戳
     */
    public static long afterSixMonthsTimestamp(long timestamp) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(timestamp));
        c.add(Calendar.MONTH, -6);
        return c.getTime().getTime() / 1000;
    }

    /**
     * 时间戳转时间
     *
     * @return yyyy-MM-dd  HH:mm
     */
    public static String timestampToTime(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
        int i = Integer.parseInt(time);
        return sdr.format(new Date(i * 1000L));
    }

    /**
     * 时间戳转时间
     *
     * @return yyyy年MM月dd日
     */
    public static String timestampToTimeStyle_2(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy年MM月dd日");
        int i = Integer.parseInt(time);
        return sdr.format(new Date(i * 1000L));
    }

    /**
     * 时间戳转时间
     *
     * @return MM-dd HH:mm
     */
    public static String timestampToTimeStyle_3(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("MM-dd HH:mm");
        int i = Integer.parseInt(time);
        return sdr.format(new Date(i * 1000L));
    }

    /**
     * 时间戳转时间
     *
     * @return MM-dd
     */
    public static String timestampToTimeStyle_4(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("MM-dd");
        int i = Integer.parseInt(time);
        return sdr.format(new Date(i * 1000L));
    }

    public static String timestampToTimeStyle_3(int time) {
        return timestampToTimeStyle_3(String.valueOf(time));
    }

    public static String timestampToTimeStyle_4(int time) {
        return timestampToTimeStyle_4(String.valueOf(time));
    }

    public static String timestampToTime(int time) {
        return timestampToTime(String.valueOf(time));
    }
}
